package pl.edu.mimuw.irs.rcp.controller.part;

import org.eclipse.gef.EditPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;

import pl.edu.mimuw.irs.core.model.design.IRSRequirement;
import pl.edu.mimuw.irs.core.model.design.processing.Requirement;
import pl.edu.mimuw.irs.core.model.design.processing.Role;
import pl.edu.mimuw.irs.core.util.Converter;
import pl.edu.mimuw.irs.rcp.view.figure.FigureWrapper;
import pl.edu.mimuw.irs.rcp.view.figure.IRSRequirementShape;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-21
 */
public class IRSRequirementEditPart extends IRSPlaceEditPart implements EditPart {

	// *** Attributes

	// *** Methods

	protected NodeShape getNodeShape() {
		return NodeShape.IRSREQUIREMENT;
	}
	
	public void attachRequirement(Role requirement) {
		IRSRequirement irsRequirement = Converter.asIRSRequirement(getNode());
		irsRequirement.getRequirements().add(new Requirement());
		
		refresh();
	}

	public void attachRequirement(Requirement requirement) {
		IRSRequirement irsRequirement = Converter.asIRSRequirement(getNode());
		irsRequirement.getRequirements().add(requirement);
		
		refresh();
	}
	
	@Override
	protected void refreshVisuals() {
		super.refreshVisuals();
		
		IRSRequirement irsRequirement = Converter.asIRSRequirement(getNode());
		FigureWrapper wrapper = (FigureWrapper)getFigure();
		
		if (!irsRequirement.getRequirements().isEmpty()) {
			wrapper.getLabel().setFont(new Font(null, "Arial", 8, SWT.BOLD));
			IRSRequirementShape shape = (IRSRequirementShape) wrapper.getFigure();
			shape.setEmpty(false);
		} else {
			wrapper.getLabel().setFont(new Font(null, "Arial", 8, SWT.NONE));
			IRSRequirementShape shape = (IRSRequirementShape) wrapper.getFigure();
			shape.setEmpty(true);
		}
		
	}
}
